<?php

class UactionController extends Controller_Base
{

    /**
     * 列表页
     */
    public function record_listAction()
    {
        header('content-type:text/html;charset=utf-8;');
        SmartyAdapter::$templateName = 'uaction/record_list';
        $request = $this->getRequest();
        $action_type = trim($request->getQuery('action_type', '999'));
        $end_time = trim($request->getQuery('end_time', ''));
        $start_time = trim($request->getQuery('start_time', ''));
        $pn = intval($this->getRequest()->getQuery('page', 1));
        $pageQuery = array();
        if ( $action_type != 999 || ($start_time && $end_time)) {
           /* $last['source_type'] = $source_type;
            $pageQuery['source_type'] = $source_type;
            if ($source_type != 999 && $source_type != 0) {
                $where[] = 'source_type=' . $source_type;
                $pageQuery['source_type'] = $source_type;
                $last['source_type'] = $source_type;
            }*/
            if ($action_type != 999 && $action_type != 0) {
                $where[] = 'action_type=' . $action_type;
                $pageQuery['action_type'] = $action_type;
                $last['action_type'] = $action_type;
            }
            if ($start_time) {
                $start_time_stamp = strtotime($start_time);
                $where[] = 'action_time>=' . $start_time_stamp;
                $pageQuery['start_time'] = $start_time;
                $last['start_time'] = $start_time;
            }
            if ($end_time) {
                $end_time_stamp = strtotime($end_time)+86400;
                $where[] = 'action_time<=' . $end_time_stamp;
                $pageQuery['end_time'] = $end_time;
                $last['end_time'] = $end_time;
            }
            $limit = 10;
            $total = Module_Uaction_UactionRecord::getInstance()->getAllBySearch(array('count(*) as total'), array('where' => $where));
            $total = $total ? $total[0]['total'] : 0;
            $start = ($pn - 1) * $limit;
            $records = Module_Uaction_UactionRecord::getInstance()->getAllBySearch(array('*'), array('where' => $where, 'start' => $start, 'order' => 'id DESC', 'limit' => $limit));
            if ($records) {
                $li_role = Module_User_Role::getInstance()->getAllBySearch();
                $li_role = array_column($li_role, 'title', 'id');
                SmartyAdapter::assign('li_role', $li_role);
            }
            $tatalPage = ceil($total / $limit);
            SmartyAdapter::assign('curPageNum', $pn);
            SmartyAdapter::assign('list', $records);
            SmartyAdapter::assign('last', $last);
            SmartyAdapter::assign('totalPage', $tatalPage);
            SmartyAdapter::assign('totalnum', $total);
            SmartyAdapter::assign('page_query', http_build_query($pageQuery));
        }
        SmartyAdapter::assign('source_type_arr', Module_Uaction_UactionRecord::$source_type_arr);
        SmartyAdapter::assign('action_type_arr', Module_Uaction_UactionRecord::$action_type_arr);
        SmartyAdapter::assign('action_res_arr', Module_Uaction_UactionRecord::$action_res_arr);
    }
}
